<?php
// 主页
namespace Mobile\Controller;

use Home\Model\SiteModel;
use Home\Model\ArticleModel;
use Home\Model\CategoryModel;
use Home\Model\CommentModel;
use Home\Model\SearchModel;
use Home\Model\TagModel;
use Home\Model\UserModel;
use Home\Model\BlogModel;
use Home\Controller\CommonController;

class IndexController extends CommonController {
	public function _initialize() {
		$tag = new TagModel ();
		$this->hotTags = $tag->getHotTag ( 21 );
	}
	public function index() {
		$site = new SiteModel ();
		$article = new ArticleModel ();
		$data ['topNav'] = 'index';

		// 热门花卉
		$data ['site'] ['top'] = $site->getSortSite ( '', 12 );

		// 花卉文章
		$data ['article'] ['zixun'] = $article->getCategoryArticle ( 26, 5 );
		$data ['article'] ['yangzhi'] = $article->getCategoryArticle ( 10, 5 );
		$data ['article'] ['shinei'] = $article->getCategoryArticle ( 27, 5 );

		// 网站seo信息
		$data ['seo'] ['title'] = '花卉图片大全，花卉养殖 - ' . C ( 'site_name' );
		$data ['seo'] ['keywords'] = '花卉网,花卉,花卉图片,花卉养殖,花草图片,室内花卉,花卉图片大全,花卉名称';
		$data ['seo'] ['description'] = '枫桥居花卉网收入了大多数花卉图片及名称,花卉养殖信息,室内花卉和花草图片.成为花友们热爱的花卉交流平台,每天有成千上万的花友们在这交流花卉养殖,花卉图片等信息.网站更新花卉内容质量高,专业性很强：hua.fengiaoju.com';

		$this->data = $data;
		$this->display ();
	}
	public function category() {
		$cid = I ( 'get.cid' ) ? I ( 'get.cid' ) : I ( 'get.url' );
		$category = new CategoryModel ();
		$article = new ArticleModel ();
		$where = 'type="article"';

		// 获取分类列表
		$data ['category'] = $category->search ( $where );

		// 获取分类信息
		$data ['category'] ['info'] = $category->getInfo ( $cid );

		// 获取分类下的文章
		$data ['article'] = $article->getCategoryArticle ( $data ['category'] ['info'] ['id'] );

		// 热门推荐
		$data ['article'] ['hot'] = $article->getHotArticle ( '', 7 );

		// 网站seo信息
		$data ['seo'] ['title'] = $data ['category'] ['info'] ['name'] . (intval ( $_REQUEST ['page'] ) ? '_第' . $_REQUEST ['page'] . '页' : '') . ' - ' . C ( 'site_name' );
		$data ['seo'] ['keywords'] = $data ['category'] ['info'] ['name'] . ',' . $data ['category'] ['info'] ['name'] . '图片,花卉,花卉图片,花卉养殖,花草图片,办公室内花卉,花卉图片大全';
		$data ['seo'] ['description'] = $data ['category'] ['info'] ['name'] . '，' . $data ['category'] ['info'] ['intro'] . ' - ' . C ( 'site_name' );

		$this->data = $data;
		$this->display ();
	}
	public function sitecategory() {
		$cid = I ( 'get.cid' ) ? I ( 'get.cid' ) : I ( 'get.url' );
		$category = new CategoryModel ();
		$article = new ArticleModel ();
		$site = new SiteModel ();
		$where = 'type="site"';

		// 获取分类列表
		$data ['category'] = $category->search ( $where );

		// 获取分类信息
		$data ['category'] ['info'] = $category->getInfo ( $cid );

		if ($data ['category'] ['info'] ['type'] != 'site') {
			$this->error404 ( '您访问的栏目不存在' );
		}

		// 获取分类下的小站
		$data ['site'] = $site->getCategorySite ( $data ['category'] ['info'] ['id'] );

		// 网站seo信息
		$data ['seo'] ['title'] = $data ['category'] ['info'] ['name'] . '_' . $data ['category'] ['info'] ['name'] . '图片大全' . (intval ( $_REQUEST ['page'] ) ? '_第' . $_REQUEST ['page'] . '页' : '') . ' - ' . C ( 'site_name' );
		$data ['seo'] ['keywords'] = $data ['category'] ['info'] ['name'] . ',' . $data ['category'] ['info'] ['name'] . '大全,' . $data ['category'] ['info'] ['name'] . '图片,花卉图片,花卉养殖,花卉图片大全';
		$data ['seo'] ['description'] = $data ['category'] ['info'] ['name'] . '，' . $data ['category'] ['info'] ['intro'] . ' - ' . C ( 'site_name' );

		$this->data = $data;
		$this->display ( 'site_category' );
	}
	public function siteshow() {
		$cid = I ( 'get.cid' );
		$id = I ( 'get.id' ) ? I ( 'get.id' ) : I ( 'get.url' );
		$category = new CategoryModel ();
		$article = new ArticleModel ();
		$site = new SiteModel ();
		$comment = new CommentModel ();
		$where = 'type="article"';

		// 获取分类信息
		$data ['category'] ['info'] = $category->getInfo ( $cid );

		// 获取小站信息
		$data ['site'] ['info'] = $site->getInfo ( $id );

		if ($data ['category'] ['info'] ['id'] != $data ['site'] ['info'] ['cid']) {
			$this->error404 ( '您访问的内容不存在' );
		}

		// 获取评论
		$data ['comment'] = $comment->getComment ( $data ['site'] ['info'] ['id'], 'site' );

		// 热门小站
		$data ['site'] ['sort'] = $site->getHotSite ( '', 6 );

		// 网站seo信息
		$keyword = make_tags ( $data ['site'] ['info'] ['name'] . ',' . $data ['site'] ['info'] ['keyword'] . ',' . $data ['category'] ['info'] ['name'] );
		$data ['seo'] ['title'] = $data ['site'] ['info'] ['name'] . ',' . $data ['site'] ['info'] ['name'] . '图片 - ' . C ( 'site_name' );
		$data ['seo'] ['keywords'] = $keyword ['str'];
		$data ['seo'] ['description'] = cut_str ( $data ['site'] ['info'] ['text200'], 100, '' ) . ' - ' . C ( 'site_name' ) . ' ' . $data ['category'] ['info'] ['name'];

		$this->data = $data;
		$this->display ( 'site_show' );
	}
	public function siteimage() {
		$cid = I ( 'get.cid' );
		$id = I ( 'get.id' ) ? I ( 'get.id' ) : I ( 'get.url' );
		$category = new CategoryModel ();
		$article = new ArticleModel ();
		$site = new SiteModel ();
		$comment = new CommentModel ();
		$where = 'type="article"';

		// 获取分类信息
		$data ['category'] ['info'] = $category->getInfo ( $cid );

		// 获取小站信息
		$data ['site'] ['info'] = $site->getInfo ( $id );

		if ($data ['category'] ['info'] ['id'] != $data ['site'] ['info'] ['cid']) {
			$this->error404 ( '您访问的内容不存在' );
		}

		// 获取评论
		$data ['comment'] = $comment->getComment ( $data ['site'] ['info'] ['id'], 'site' );

		// 热门小站
		$data ['site'] ['sort'] = $site->getHotSite ( '', 6 );

		// 网站seo信息
		$keyword = make_tags ( $data ['site'] ['info'] ['name'] . ',' . $data ['site'] ['info'] ['keyword'] . ',' . $data ['category'] ['info'] ['name'] );
		$data ['seo'] ['title'] = $data ['site'] ['info'] ['name'] . ',' . $data ['site'] ['info'] ['name'] . '图片  - ' . C ( 'site_name' );
		$data ['seo'] ['keywords'] = $keyword ['str'];
		$data ['seo'] ['description'] = cut_str ( $data ['site'] ['info'] ['text200'], 100, '' ) . ' - ' . C ( 'site_name' ) . ' ' . $data ['category'] ['info'] ['name'];

		$data ['url'] = $data ['site'] ['info'] ['url'];

		$this->data = $data;
		$this->display ( 'site_image' );
	}
	public function article() {
		$cid = I ( 'get.cid' );
		$id = I ( 'get.id' ) ? I ( 'get.id' ) : I ( 'get.url' );
		$category = new CategoryModel ();
		$article = new ArticleModel ();
		$site = new SiteModel ();
		$comment = new CommentModel ();
		$where = 'type="article"';

		// 获取分类信息
		$data ['category'] ['info'] = $category->getInfo ( $cid );

		// 获取文章信息
		$data ['article'] ['info'] = $article->getInfo ( $id );

		if ($data ['category'] ['info'] ['id'] != $data ['article'] ['info'] ['cid']) {
			$this->error404 ( '您访问的文章不存在' );
		}

		// 获取评论
		$data ['comment'] = $comment->getComment ( $data ['article'] ['info'] ['id'], 'article' );

		// 热门小站
		$data ['site'] ['sort'] = $site->getHotSite ( '', 6 );

		// 网站seo信息
		$keyword = make_tags ( $data ['article'] ['info'] ['title'] . ',' . $data ['article'] ['info'] ['tag'] . ',' . $data ['category'] ['info'] ['name'] );
		$data ['seo'] ['title'] = $data ['article'] ['info'] ['title'] . ' - ' . C ( 'site_name' );
		$data ['seo'] ['keywords'] = $keyword ['str'];
		$data ['seo'] ['description'] = cut_str ( $data ['article'] ['info'] ['text200'], 100, '' ) . ' - ' . C ( 'site_name' ) . ' ' . $data ['category'] ['info'] ['name'];

		$this->data = $data;
		$this->display ( 'article' );
	}
	public function search() {
		$keyword = trim ( $_REQUEST ['keyword'] );

		$search = new SearchModel ();
		$site = new SiteModel ();

		// 热门小站
		$data ['site'] ['sort'] = $site->getHotSite ( '', 6 );

		$data ['search'] = $search->search ( $keyword );
		$data ['search'] ['name'] = $keyword;
		$data ['search'] ['intro'] = "<p>以下是搜索<strong>{$keyword}</strong>的结果</p><p>如果没有搜索到您想要的结果，请尝试拆分关键词。也可以加QQ群或者关注微信订阅号：花卉信息网</p>";

		// 网站seo信息
		$data ['seo'] ['title'] = $keyword . (intval ( $_REQUEST ['page'] ) ? '_第' . $_REQUEST ['page'] . '页' : '') . ' - ' . C ( 'site_name' );
		$data ['seo'] ['keywords'] = "{$keyword},{$keyword}信息,{$keyword}文章,花卉,花卉检索,搜索花卉";
		if ($data ['search'] ['siteIntro']) {
			$data ['seo'] ['description'] = $data ['search'] ['siteIntro'];
		} else {
			$data ['seo'] ['description'] = "这是搜索“{$keyword}”的结果！" . C ( 'site_name' ) . "为您检索出以下关于{$keyword}信息和{$keyword}内容，请查点击相关链接看文章和图片。" . C ( 'site_name' ) . "将提供更多更专业的{$keyword}信息给您。";
		}
		$this->data = $data;
		$this->display ( 'search' );
	}
	public function tag() {
		$name = trim ( $_REQUEST ['name'] );

		$tag = new TagModel ();
		$site = new SiteModel ();

		// 热门小站
		$data ['site'] ['sort'] = $site->getHotSite ( '', 6 );

		$data ['tag'] = $tag->search ( $name );
		$data ['tag'] ['name'] = $name;
		$data ['tag'] ['intro'] = "<p>以下是关于<strong>$name</strong>的标签</p><p>您也可以加QQ群或者关注微信订阅号：花卉信网</p>";

		// 网站seo信息
		$data ['seo'] ['title'] = $name . ",关于{$name}的标签" . (intval ( $_REQUEST ['page'] ) ? '_第' . $_REQUEST ['page'] . '页' : '') . ' - ' . C ( 'site_name' );
		$data ['seo'] ['keywords'] = "{$name},{$name}信息,{$name}文章,{$name}标签,花卉,花卉图片,花卉养殖";
		if ($data ['tag'] ['siteIntro']) {
			$data ['seo'] ['description'] = $data ['tag'] ['siteIntro'];
		} else {
			$data ['seo'] ['description'] = "关于“{$name}”标签的结果！" . C ( 'site_name' ) . "为您检索出以下关于{$name}标签的信息、内容、图片和资讯。" . C ( 'site_name' ) . "将提供更多更专业的{$name}资料给您。";
		}
		$this->data = $data;
		$this->display ( 'tag' );
	}
	public function tupian() {
		$data ['topNav'] = 'tupian';
		$article = new ArticleModel ();
		$site = new SiteModel ();
		$where = 'type="site"';

		$data ['site'] = $site->search ( '1', 1, 'sort desc,updatetime desc', 40 );

		// 网站seo信息
		$data ['seo'] ['title'] = '花卉图片,花卉图片及名称大全 - ' . C ( 'site_name' );
		$data ['seo'] ['keywords'] = '花卉网,花卉,花卉图片,花卉图片名称,花草图片,室内花卉图片,花卉图片大全,家庭花卉图片';
		$data ['seo'] ['description'] = '枫桥居花卉网收录了各种常见花卉图片及名称大全，网站有丰富的室内花卉图片、家庭花卉图片、常见花卉图片及名称。欢迎喜欢种花养花的朋友来枫桥居花卉网交流养花知识。';

		$this->data = $data;
		$this->display ();
	}
	public function huahui() {
		$data ['topNav'] = 'huahui';
		$article = new ArticleModel ();
		$site = new SiteModel ();
		$where = 'type="site"';

		// 访问前40个小站
		$data ['site'] = $site->search ( '1', 1, 'sort desc ,viewnum desc', 40 );

		// 网站seo信息
		$data ['seo'] ['title'] = '花卉名称,花卉大全,花卉养殖方法 - ' . C ( 'site_name' );
		$data ['seo'] ['keywords'] = '花卉名称,花卉大全,花卉养殖,室内花养殖,花卉养殖大全,办公室养花,家庭花卉养殖,花卉养殖,花卉,养花网';
		$data ['seo'] ['description'] = '枫桥居花卉网收录了各种常见花卉养殖方法，网站整理了很多室内花卉养殖方法、家庭花卉养殖方法、常见花卉养殖方法及养花视频。欢迎喜欢种花养花的朋友来枫桥居花卉网交流养花知识。';

		$this->data = $data;
		$this->display ();
	}
	public function refindpassword() {
		$uid = intval ( $_REQUEST ['uid'] );
		$token = $_REQUEST ['token'];
		$rs = check_token ( $uid, $token );
		if ($rs ['status']) {
			$user = new UserModel ();
			$data ['user'] = $user->getUserInfo ( $uid );
			$this->data = $data;
			$this->display ();
		} else {
			$this->error ( $rs ['msg'] );
		}
	}
	public function doActivation() {
		$uid = intval ( $_REQUEST ['uid'] );
		$token = $_REQUEST ['token'];
		$rs = check_token ( $uid, $token );
		if ($rs ['status']) {
			$user = new UserModel ();
			$rs = $user->doActivation ( $uid );
			$this->success ( $rs ['msg'], '/' );
		} else {
			$this->error ( $rs ['msg'] );
		}
	}
	public function blogshow() {
		$id = intval ( $_REQUEST ['id'] );
		$blog = new BlogModel ();
		$site = new SiteModel ();
		$user = new UserModel ();
		$comment = new CommentModel ();
		$where = 'type="blog"';

		// 获取日志信息
		$data ['blog'] ['info'] = $blog->getInfo ( $id );

		// 猜你喜欢 - 热门日记
		$data ['blog'] ['love'] = $blog->getHotBlog ( '', 10, $id );

		// 用户其它日记
		$data ['blog'] ['more'] = $blog->getUserBlog ( $data ['blog'] ['info'] ['uid'], 10, $id );

		// 用户
		$data ['user'] ['info'] = $user->getUserInfo ( $data ['blog'] ['info'] ['uid'] );

		// 推荐小站
		$data ['site'] ['top'] = $site->getSortSite ( '', 5 );

		// 获取评论
		$data ['comment'] = $comment->getComment ( $data ['blog'] ['info'] ['id'], 'blog' );

		// 网站seo信息
		$data ['seo'] ['title'] = '';
		$data ['seo'] ['keywords'] = '';
		$data ['seo'] ['description'] = '';

		$this->data = $data;
		$this->display ( 'detail' );
	}
}
